home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / vectlib.exe / MATRIX.H < prev    next >
C/C++ Source or Header  |  1991-07-25  |  2KB  |  56 lines

  1. // Matrix.h, by Scott Litvinoff
  2. // 3x3 Matrix class definition
  3. #include "vect3.h"
  4. #include "iostream.h"
  5. #include "float.h"
  6. #include "math.h"
  7. #include "stdlib.h"
  8. #include "stddef.h"
  9. #include "string.h"
  10.  
  11. class matrix
  12. {
  13.     vector3 row1,row2,row3,col1,col2,col3;
  14.  
  15.     public:
  16.     matrix(double a11=0,double a12=0,double a13=0,double a21=0,double a22=0,double a23=0,double a31=0,double a32=0,double a33=0)
  17.     {
  18.         row1=vector3(a11,a12,a13);               // Matrix constructor with
  19.         row2=vector3(a21,a22,a23);               // inputs given as:
  20.         row3=vector3(a31,a32,a33);               // doubles a11...a13, then
  21.         col1=vector3(a11,a21,a31);               // doubles a21...a23, then
  22.         col2=vector3(a12,a22,a32);               // doubles a31...a33
  23.         col3=vector3(a13,a23,a33);
  24.     }
  25.     matrix(vector3 r1,vector3 r2,vector3 r3)
  26.     {
  27.         row1=r1;                                 // Matrix constructor using
  28.         row2=r2;                                 // Three vectors representing
  29.         row3=r3;                                 // Rows 1,2, and 3
  30.         col1=vector3(r1.x(),r2.x(),r3.x());
  31.         col2=vector3(r1.y(),r2.y(),r3.y());
  32.         col3=vector3(r1.z(),r2.z(),r3.z());
  33.     }
  34.     friend matrix operator+(matrix&,matrix&);    // Binary matrix addition
  35.  
  36.     friend matrix operator-(matrix&,matrix&);    // Binary matrix subtraction
  37.  
  38.     friend matrix operator*(matrix&,matrix&);    // Binary matrix multiplication
  39.  
  40.     friend matrix operator+(matrix&);            // Returns same as input
  41.  
  42.     friend matrix operator-(matrix&);            // Unary matrix negation
  43.  
  44.     friend matrix operator*(double,matrix&);     // Scalar matrix multiplication
  45.  
  46.     friend matrix operator*(matrix&,double);     // Scalar matrix multiplication
  47.  
  48.     double det(matrix&);                         // Matrix determinant
  49.  
  50.     matrix tran();                               // Matrix transpose
  51.  
  52.     double aij(unsigned char,unsigned char);     // Returns element at location
  53.                                                  // (i,j)
  54.     void print();                                // Outputs matrix to stream
  55. };
  56.